import {
    getUnStandProductProcessInfoByUnstandTypeId,
    addUnStandProductProcessInfo,
    getPagedProductProcessInfoByProductId,
  } from '@/services/design/productDesign';
  import { PageHeaderWrapper } from '@ant-design/pro-layout';
  import type { ActionType, ProColumns } from '@ant-design/pro-table';
  import ProTable from '@ant-design/pro-table';
  import { EditableProTable } from '@ant-design/pro-components';
  import { Button, Form, Input, message, Modal, Row, Col, InputNumber } from 'antd';
  import { CheckOutlined } from '@ant-design/icons';
  import { sortTran, filterTran } from '@/utils/requestUtil';
  import React, { useEffect, useRef, useState } from 'react';
  import { history } from 'umi';
  import { Ellipsis } from '@/components/Ellipsis';
  const ProcessInfo: React.FC<{}> = (props) => {
    const actionRef = useRef<ActionType>();
  
    const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
    const [confirmLoading, setComfirmLoading] = useState(false);//加载控制状态
    const currentBatchProductId = props.batchProductId;
  
    type DataSourceType = {
      id: React.Key;
      title?: string;
      readonly?: string;
      decs?: string;
      state?: string;
      created_at?: number;
      update_at?: number;
      children?: DataSourceType[];
    };
  
    const columns: ProColumns[] = [
      // {
      //   title: '序号',
      //   dataIndex: 'index',
      //   valueType: 'index',
      //   width: 80,
      // },
      {
        title: '工序顺序',
        dataIndex: 'sequence',
        width: 90,
        align: 'center',
        sorter: true,
        readonly: true,
      },
      {
        title: '工序编号',
        dataIndex: 'processCode',
        width: 140,
        align: 'center',
        sorter: true,
        readonly: true,
      },
      {
        title: '工序名称',
        dataIndex: 'processName',
        width: 200,
        align: 'center',
        sorter: true,
        render: (text) => <>{Ellipsis(text)}</>,
        readonly: true,
      },
      {
        title: '是否生产工序',
        dataIndex: 'isProductionProcess',
        width: 140,
        align: 'center',
        sorter: true,
         render: (text, record, _, action) => {
           return <div>{record.isProductionProcess == 1 ? '是' : '否'}</div>;
         },
        readonly: true,
      },
      {
        title: '是否需要自检', //表头显示的名称
        search: false,
        align: 'center',
        sorter: true,
        dataIndex: 'showSelfInspection',
        width: 120,
        render: (text) => {
          return (
          <div>{text === 1 ? '是' : '否'}</div>
          )
        }
      },
      {
        title: '标准工时(H)',
        dataIndex: 'standWorkHour',
        align: 'center',
        sorter: true,
        render: (text, record, _, action) => {
          return <div>{record.standWorkHour.toFixed(2)}</div>;
        },
        renderFormItem: ({ index }) => {
          return <InputNumber type="number" min={0.01} step="0.01" placeholder="保留两位小数" />;
        },
      },
      {
        title: '标准周期(天)',
        dataIndex: 'standCycle',
        align: 'center',
        sorter: true,
        render: (text) => {
          return <div>{text}</div>;
        },
        renderFormItem: ({ index }) => {
          return <InputNumber type="number" min={0} precision={0} placeholder="请输入正整数" />;
        },
      },
    ];
  
  
    return (
      <PageHeaderWrapper title={false} breadcrumb={undefined}>
        <EditableProTable<DataSourceType>
          rowKey="processId"
          headerTitle="柜体工时周期查看"
          actionRef={actionRef} //用于触发刷新操作等，看api
          // maxLength={5}到了最大行数，新建按钮消失
          recordCreatorProps={false}
          loading={confirmLoading}
          toolBarRender={(action, { selectedRows }) => [
          ]}
          scroll={{ x: 570, y: 350 }}
          columns={columns}
          request={async (params = {}, sort, filter) => {
            setComfirmLoading(true);
            let res = {};
            res.productId = currentBatchProductId;
            res.pageEntity = {
                current:1,
                pageSize:100,
                filters:[],
                sorters:[],
            }
            const result = await getPagedProductProcessInfoByProductId(res);
            console.log(result,'result1')
            setComfirmLoading(false);
            return {
              data: result.data.content,
              total: result.data.totalElements,
              success: result.success,
            };
          }}
          editable={{
            type: 'multiple',
            editableKeys,
            onSave: async (rowKey, data, row) => {},
            onChange: setEditableRowKeys,
            actionRender: (row, config, defaultDom) => {
              return [defaultDom.save, defaultDom.cancel];
            },
          }}
        />
      </PageHeaderWrapper>
    );
  };
  export default ProcessInfo;
  